const webpack = require('webpack')
const path = require('path')

const resolve = dir => {
  return path.join(__dirname, dir)
}

// const BASE_URL = process.env.NODE_ENV === 'production'
//   ? '/'
//   : '/'

const port = 8080 // dev port

module.exports = {
  publicPath: process.env.VUE_APP_PUBLIC_PATH,
  // 如果你不需要使用eslint，把lintOnSave设为false即可
  lintOnSave: true,
  configureWebpack: {
    externals: {
      // 'echarts-gl': 'echarts-gl'
    },
    plugins: [
      new webpack.ProvidePlugin({
        $: 'jquery',
        jQuery: 'jquery',
        'windows.jQuery': 'jquery'
      })
    ]
  },
  chainWebpack: config => {
    config.resolve.alias
      .set('@', resolve('src')) // key,value自行定义，比如.set('@@', resolve('src/components'))
      .set('_c', resolve('src/components'))
  },
  // 设为false打包时不生成.map文件
  productionSourceMap: false,
  // 这里写你调用接口的基础路径，来解决跨域，如果设置了代理，那你本地开发环境的axios的baseUrl要写为 '' ，即空字符串
  devServer: {
    port: port,
    host: '0.0.0.0',
    overlay: {
      warnings: false,
      errors: true
    },
    proxy: {
      '/api-dev': {
        target: process.env.VUE_APP_BASE_PROXY_TARGET_API,
        secure: true,
        changeOrigin: true,
        pathRewrite: { '^/api-dev': '' }
      }
      // '/api': {
      //   target: process.env.VUE_APP_BASE_PROXY_TARGET_API,
      //   changeOrigin: true
      // }
    }
  }
}
